package cn.sczhyt.modules.szhy.controller;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Map;

import cn.sczhyt.modules.szhy.entity.MeetingFileEntity;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingVideoEntity;
import cn.sczhyt.modules.szhy.service.MeetingVideoService;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 会议视频
 *
 * @author luojialin
 * @email 78357966@qq.com
 * @date 2021-04-23 09:45:24
 */
@RestController
@RequestMapping("szhy/meetingvideo")
public class MeetingVideoController {
    @Autowired
    private MeetingVideoService meetingVideoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam String meetingId,
                  @RequestParam(defaultValue = "1") Integer page,
                  @RequestParam(defaultValue = "20") Integer limit
    ){
        IPage<MeetingVideoEntity> iPage= meetingVideoService.findAll(page,limit,meetingId);
        PageUtils pageUtils = new PageUtils(iPage);
        return R.ok().put("data", pageUtils);
    }


    /**
     * 获取视频文件地址
     */
    @RequestMapping("/info/{videoId}")
    public R info(@PathVariable("videoId") String videoId){

		MeetingVideoEntity meetingVideo = meetingVideoService.getById(videoId);

        return R.ok().put("data", meetingVideo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestParam("file") MultipartFile[] files, @RequestParam String meetingId){

        meetingVideoService.saveMeetingVideo(files,meetingId);

        return R.ok();
    }

    /**
     * 文件下载
     */
    @ApiOperation("文件下载")
    @GetMapping("/download")
    public R download(@RequestParam String videoId, HttpServletResponse response, HttpServletRequest request) throws UnsupportedEncodingException {

        meetingVideoService.download(videoId,response,request);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MeetingVideoEntity meetingVideo){
		meetingVideoService.updateById(meetingVideo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] videoIds){
		meetingVideoService.removeByIds(Arrays.asList(videoIds));

        return R.ok();
    }

}
